import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/common/xindong_methods.dart';
import 'package:xindong/manager/xindong_page_singleton.dart';
import 'package:xindong/manager/xindong_user_controller.dart';
import 'package:xindong/res/assets_res.dart';
import 'package:xindong/routes/user/volleyList/xindong_volley_list_yemian.dart';
import 'package:xindong/routes/user/wallet/xindong_recharge_ctr.dart';
import 'package:xindong/routes/user/wallet/xindong_recharge_list_view.dart';
import 'package:xindong/utils/xindong_image_util.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/common/xindong_app_bar_text_button.dart';
import 'package:xindong/widgets/common/xindong_button.dart';

class XinDongRechargeYeMian extends StatefulWidget {
  const XinDongRechargeYeMian({super.key});

  @override
  State<XinDongRechargeYeMian> createState() => _XinDongRechargeYeMianState();
}

class _XinDongRechargeYeMianState extends State<XinDongRechargeYeMian> {
  @override
  void initState() {
    super.initState();
    XinDongUserController.to.requestUserVolley();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: XinDongAppBar(
        "充值中心",
        elevation: 0,
        actions: [
          XinDongAppBarTextButton(
            name: '账单',
            onTap: () {
              XinDongPageSingleton.instance.pushYeMian(const XinDongVolleyListYeMian());
            },
          ),
        ],
      ),
      body: Stack(
        children: [
          Positioned(
            left: 0,
            right: 0,
            top: 0,
            child: Container(
              height: 80,
              padding: const EdgeInsets.only(left: 16, right: 16, bottom: 26),
              decoration: const BoxDecoration(
                image: DecorationImage(image: AssetImage(AssetsRes.RECHARGE_TOP_BG), fit: BoxFit.cover),
              ),
              child: GetBuilder<XinDongUserController>(builder: (controller) {
                return Row(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  children: [
                    const Text(
                      "金币余额",
                      style: TextStyle(color: DZColors.contentColor, fontSize: 12, height: 2.5),
                    ),
                    const SizedBox(width: 10),
                    Text(
                      controller.balance,
                      style: const TextStyle(color: DZColors.mainColor, fontSize: 20),
                    ),
                    const SizedBox(width: 10),
                    ImageUtil.asset(AssetsRes.ICON_GOLD_COIN, width: 20, height: 26),
                  ],
                );
              }),
            ),
          ),
          Positioned.fill(
            top: 70,
            child: ListView(
              physics: const ClampingScrollPhysics(),
              children: [
                Container(
                  padding: const EdgeInsets.all(16),
                  decoration: const BoxDecoration(
                    color: DZColors.dialog,
                    borderRadius: BorderRadius.only(topLeft: Radius.circular(16), topRight: Radius.circular(16)),
                  ),
                  child: const XinDongRechargeListView(),
                ),
                const Padding(
                  padding: EdgeInsets.all(16.0),
                  child: Text(
                    "温馨提示：如您已支付成功，金币余额没有增加，请重新进来当前页面，平台可能稍有延误！",
                    style: TextStyle(color: DZColors.contentColor, fontSize: 14),
                  ),
                ),
                SizedBox(height: 25 + kButtonHeight + bottomBarHeight + 30),
              ],
            ),
          ),
          Positioned(
            bottom: 30 + bottomBarHeight,
            left: 16,
            right: 16,
            child: SizedBox(
              height: kButtonHeight,
              child: XinDongCommonButton(
                '立即充值',
                onTap: () => XinDongRechargeCtr.to.onTapBuy(),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
